package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 添加联系人
     *  接口路径：POST  /contacts
     *  请求参数：
     *      Body：userId
     *  返回值：null
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        String temp = map.get("userId").toString();
        Long friendId = Long.valueOf(temp); //好友id
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询联系人列表
     *  接口路径：  GET  /contacts
     *  请求参数；
     *      Query：page，pagesize
     *  返回值：
     *      PageResult  --List<vo>
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10")  Integer pagesize) {
        PageResult vo = messagesService.findContacts(page,pagesize) ;
        return ResponseEntity.ok(vo);
    }
}
